﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Utility
{
    public static class Utility
    {
        public static string usershutdown = "User shut down this Thread";
        public static string ranoutofspace = "System shut down due to insufficient space";
        public static string playingwithfiles = "System shut down due to file access issues";
        public static string completedcodegen = "System shut down this thread due to unit of work complete";
        public static string CodegenSFDfilter = "txt files (*.txt)|*.txt|All files (*.*)|*.*|dic files (*.dic)|*.dic";
        public static string CodegenConfigSFDfilter = "codegen config files (*.cog)|*.cog|All files (*.*)|*.*";
        public static string FilelocationstabINVALIDfilepath = "\r\n!!Please select another file path the currently selected one is invalid";
        public static string getnicecharvalueonint(int charmin)
        {
            switch (charmin)
            {
                case 0:
                    return "NUL -non standard";
                case 1:
                    return "SOH -non standard";
                case 2:
                    return "STX -non standard";
                case 3:
                    return "ETX -non standard";
                case 4:
                    return "EOT -non standard";
                case 5:
                    return "ENQ -non standard";
                case 6:
                    return "ACK -non standard";
                case 7:
                    return "BEL -non standard";
                case 8:
                    return "BS -non standard";
                case 9:
                    return "TAB -non standard";
                case 10:
                    return "LF -non standard";
                case 11:
                    return "VT -non standard";
                case 12:
                    return "FF -non standard";
                case 13:
                    return "CR -non standard";
                case 14:
                    return "SO -non standard";
                case 15:
                    return "SI -non standard";
                case 16:
                    return "DLE -non standard";
                case 17:
                    return "DC1 -non standard";
                case 18:
                    return "DC2 -non standard";
                case 19:
                    return "DC3 -non standard";
                case 20:
                    return "DC4 -non standard";
                case 21:
                    return "NAK -non standard";
                case 22:
                    return "SYN -non standard";
                case 23:
                    return "ETB -non standard";
                case 24:
                    return "CAN -non standard";
                case 25:
                    return "EM -non standard";
                case 26:
                    return "SUB -non standard";
                case 27:
                    return "ESC -non standard";
                case 28:
                    return "FS -non standard";
                case 29:
                    return "GS -non standard";
                case 30:
                    return "RS -non standard";
                case 31:
                    return "US -non standard";
                case 32:
                    return "SPACE -non standard";
                case 127:
                    return "DEL -non standard";
                default:
                    char element = (char)charmin;
                    string s = new String(new char[] { element });
                    return s;

            }


        }

        public static string GetThreadListContent(string header, List<string> notifications, string threadstate)
        {
            string content = "";
            content += header.Remove(header.IndexOf('\r')); 
            content += " Current State: [ " ;
            ////? (a.notification.Any() ? "The thread is scheduled for shutdown" : "Currently Running") : (threads == System.Threading.Tasks.TaskStatus.RanToCompletion.ToString() ? "Thread has terminated due to: (" + (a.notification.Any() ? a.notification.FirstOrDefault() + ")" : "currently uknown reason" + ")") : ThreadState(a))));
            if (threadstate == System.Threading.Tasks.TaskStatus.Running.ToString() ||
                threadstate == System.Threading.Tasks.TaskStatus.WaitingToRun.ToString())
            {
                if (notifications.Any())
                {
                    content += "Shut down in progress due to request:  (";
                    content += notifications.FirstOrDefault() + ")";
                }
                else
                {
                    content += threadstate;

                }
            }

            if (threadstate == TaskStatus.RanToCompletion.ToString())
            {
                if (notifications.Any())
                {
                    content += "This thread has shutdown for this reason: (";
                    content += notifications.FirstOrDefault() + ")";
                }
            }
            content += " ]";
            return content;
        }

        public static string GetThreadContextMenuetext(string header, List<string> notifications, string threadstate)
        {
            string content = "";
            
            
            ////? (a.notification.Any() ? "The thread is scheduled for shutdown" : "Currently Running") : (threads == System.Threading.Tasks.TaskStatus.RanToCompletion.ToString() ? "Thread has terminated due to: (" + (a.notification.Any() ? a.notification.FirstOrDefault() + ")" : "currently uknown reason" + ")") : ThreadState(a))));
            if (threadstate == System.Threading.Tasks.TaskStatus.Running.ToString() ||
                threadstate == System.Threading.Tasks.TaskStatus.WaitingToRun.ToString())
            {
                if (notifications.Any())
                {
                    content += "Shut down currently inprogress due to request:  (";
                    content += notifications.FirstOrDefault() + ")";
                }
                else
                {

                    content += "Shut Down Code Generation Process";

                }
            }

            if (threadstate == TaskStatus.RanToCompletion.ToString())
            {
                if (notifications.Any())
                {
                    content += "This thread has terminated execution for reason: (";
                    content += notifications.FirstOrDefault() + ")";
                }
            }

            return content;
        }
    }
}
